Skip to content

fix: update existing route index to prevent 404 on user switch #6003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

vem
Copy link
Contributor

@vem vem commented Apr 20, 2025

Description

后端访问控制路由时,切换登录账户有可能出现404错误。具体复现情况如下:
路由为两级菜单,假设

zhangsan 的菜单是
/user
/user/manage
homePath 是 /user/manage

lisi 的菜单是
/user
/user/password
homePath 是 /user/password

因为一级目录都是 /user,导致路由未更新,但是作为 homePath 的二级目录有变化,会导致登录之后出现404页面。

代码修改了 route 更新逻辑,未找到的路由仍然保持添加逻辑,找到的路由根据 index 做更新可以解决这个问题。

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an issue where outdated route data could cause navigation errors when switching users, ensuring more reliable access to the correct routes.

Copy link

changeset-bot bot commented Apr 20, 2025

⚠️ No Changeset found

Latest commit: 740e4c1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Apr 20, 2025

Walkthrough

The update revises the internal logic of the generateAccessible function within the accessible.ts file. Specifically, it changes how routes with duplicate names are handled when adding them to the root route's children. Instead of ignoring new routes with existing names, the function now replaces the old route with the new one, ensuring that the latest route data is always used. No changes were made to exported APIs or function signatures.

Changes

File(s) Change Summary
packages/effects/access/src/accessible.ts Updated logic in generateAccessible to replace existing routes with new ones by name, instead of skipping duplicates.

Poem

In the warren of routes, a new path appears,
No more stale tunnels, no 404 fears.
When names collide, the old gives way,
Fresh carrots for travelers, hip-hip-hooray!
The rabbit hops on, with routes up to date,
Navigating the garden, never missing a gate.
🥕

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/effects/access/src/accessible.ts (1)

42-42: Consider alternative to the delete operator.

The static analysis tool flagged this line due to the use of the delete operator, which can impact performance in certain JavaScript engines.

- delete route.component;
+ route.component = undefined;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b148b8e and 740e4c1.

📒 Files selected for processing (1)
  • packages/effects/access/src/accessible.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/effects/access/src/accessible.ts

[error] 48-48: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: post-update (ubuntu-latest)
🔇 Additional comments (1)
packages/effects/access/src/accessible.ts (1)

47-54: Excellent fix for the route update issue!

This implementation effectively solves the 404 error issue that occurs when switching between users with different second-level routes under the same first-level directory. By replacing the existing route instead of ignoring it, you ensure that the homePath and other route properties are properly updated.

The implementation is robust with proper index checks (index !== undefined && index !== -1) before attempting to update the route. This prevents any potential runtime errors.

🧰 Tools
🪛 Biome (1.9.4)

[error] 48-48: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

@mynetfan mynetfan changed the title fix: Update existing route index to prevent 404 on user switch fix: update existing route index to prevent 404 on user switch Apr 21, 2025
@anncwb anncwb merged commit 681c1dc into vbenjs:main Apr 28, 2025
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants